<template>
  <div>
    <van-row class="linehr">
      <van-col span="2">
        <van-icon name="arrow-left"/>
      </van-col>
      <van-col span="22">
        <van-search placeholder="请输入搜索关键词" v-model="value" />
      </van-col>
    </van-row>

    <van-tree-select :items="items" height="100%" :main-active-index.sync="activeIndex" @click-nav="getList">
      <template slot="content">
        <van-row>
          <van-col span="8" v-for="(item,index) in list" :key="index" @click="goSelect">
            <div class="goods">
              <img :src="item.src" alt />
              <div class="title">{{item.title}}</div>
            </div>
          </van-col>
        </van-row>
      </template>
    </van-tree-select>
  </div>
</template>
<script>
export default {
  data () {
    return {
      value: '',
      activeIndex: 0,
      items: [],
      list: []
    }
  },
  created () {
    this.getCategory()
  },
  methods: {
    getCategory () {
      this.$http.get('category').then(res => {
        this.items = res.data
      })
      this.$http.get('category?id=' + 0).then(res => {
        console.log(res)
        this.list = res.data
      })
    },
    getList (id) {
      this.$http.get('category?id=' + id).then(res => {
        console.log(res)
        this.list = res.data
      })
    },
    goSelect () {
      this.$router.push('/categoryselect')
    }
  }
}
</script>
<style lang="less" scoped>
.van-tree-select {
  height: 700px;
}
.van-row {
  padding: 0 10px;
  box-sizing: border-box;
  line-height: 30px;
}
.linehr {
    border-bottom: 1px solid #ccc;
}
.goods {
  width: 100%;
  padding: 5px;
  box-sizing: border-box;
  .title {
    width: 100%;
    text-align: center;
    font-size: 14px;
    color: #666;
  }
  img {
    width: 100%;
  }
}
.van-icon {
    font-size: 26px;
    padding-top: 12px;
}
</style>
